package com.shengyuan.manage_os.old.ying.erpm;


import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.CheLiangMingCheng;
import com.shengyuan.manage_os.old.ying.erpm.db.Actual_JiShi_Table;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;

import android.os.Bundle;

public class Actual_Form_TaiBanJieSu_SL extends Actual_Form_TaiBanKaiShi_JX {

	//protected PictureButton PictureButton_XiaoShiBiao, PictureButton_YouBiao;
	//protected EditText editText_xiaoshibiaoshu, editText_youbiaoshu;
	
	@Override
	public String MyID() {
		return getClass().getName();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate_copy(savedInstanceState);
		setContentView(R.layout.actual_form_taiban_ziyoushilun_jiesua);
		InitControls();
		
		//Actual_Data_Table dbo = new Actual_Data_Table(this);
		//mArrayList = dbo.getArray_Finished(0, Actual_Form_TaiBanKaiShi_SL.class.getName());
	}

	@Override
	protected void SaveJsonData() {
		IsJson1 = false; mFinished = 1; mMaxid= WorkSpaceActivityGC.mMachinery.Id ;
		SaveData();
	}
	
	protected void SaveData(){
		try {
			JsonMyID();
			getJieXieMingCheng();
			getZhongLiang();
			getHowLongTime();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			if (PictureButton_Km!=null) {
				mJson.put( PictureButton_Km.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_Km.mFileName);
			}
			//价格保存
			if (Submit_System_Setting_Data_Task.mID>=0) {
				String YuSuanJiaGe = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(Submit_System_Setting_Data_Task.mID).getString("YuSuanJiaGe");
				Double val = Double.parseDouble(YuSuanJiaGe) * Double.parseDouble( editText_helishijian.getText().toString());
				mJson.put( getString(R.string.title_actual_form_yusuanjiage),  val+"");
				mJson.put( getString(R.string.title_actual_form_jiage),  YuSuanJiaGe);
			}
			if (CheLiangMingCheng.mMachinery!=null) {
				mJson.put( getString(R.string.title_actual_form_editText_car),  CheLiangMingCheng.mMachinery.Name );
			}
		}catch (Exception e) {
		}
	}
	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_Car, sPath);
			CopyPicDest(PictureButton_Chexing, sPath);
			CopyPicDest(PictureButton_Km, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}
	
	@Override
	protected void Save_Has_Finished() {
        Actual_JiShi_Table dbo= new Actual_JiShi_Table(this);
        dbo.Save_FinishedRecord(WorkSpaceActivityGC.mMachinery.Name);
        dbo.close();
	}
	
	private void getHowLongTime() throws JSONException {
		mJson.put( getString(R.string.title_actual_form_edittext_jixieshijian), WorkSpace_TaiBanActivity_JX.mMachinery.ElapsedTime);
		mJson.put( getString(R.string.title_actual_form_edittext_jixieshiduan), WorkSpace_TaiBanActivity_JX.mMachinery.WorksTime);
	}
	
	@Override
	public Boolean IsPassed() {
//		if (GpsButton_Gps.x ==0 && GpsButton_Gps.y==0) {
//			Utility.MessageBox( GpsButton_Gps.hint );
//			return false;
//		}		
		if(!CheckEditNumber(editText_helishijian))
			return false;
		if(!CheckEditNumber(editText_xiaoshibiaoshu))
			return false;
		if(!CheckEditNumber(editText_km))
			return false;		
		if (!PictureButton_Car.IsExist()) {
			Utility.MessageBox(this, PictureButton_Car.FIELD );
			return false;
		}		
		if (!PictureButton_Chexing.IsExist()) {
			Utility.MessageBox(this, PictureButton_Chexing.FIELD );
			return false;
		}		
		if (!PictureButton_Km.IsExist()) {
			Utility.MessageBox(this, PictureButton_Km.FIELD );
			return false;
		}
		return true;
	}	
}
